/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jeff.springWebTestNG.tx;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionSynchronizationManager;

/**
 *
 * @author winnie
 */
//@Component //temporary disable the aspect until find the solution of ordered
                //tx advice
@Aspect
public class TestTxAspect implements Ordered {
    private int order;
    @Override
    public int getOrder() {
        return order;
    }
    public void setOrder(int order) {
        this.order = order;
    }

    
    @Around("tryDoingSth()")
    public void flag(ProceedingJoinPoint pjp) {
        System.out.println("begin of flag()");
        try {
            pjp.proceed();
        } catch (Throwable ex) {
            Logger.getLogger(TestTxAspect.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("at the end of flag() isSynchronizationActive = " + 
                TransactionSynchronizationManager.isSynchronizationActive());
    }
    
    @Pointcut("execution(* com.jeff.springWebTestNG.persistence.service.IGenericMyBatisPersister.tryDoingSth(..))")
    public void tryDoingSth() {}
}
